import { ElMessage } from 'element-plus';

// 定义支持的消息类型
const supportedTypes = ['success', 'warning', 'info', 'error'] as const;
type MessageType = typeof supportedTypes[number];

// 检查并返回有效的消息类型
const openmasstype = (types: string): MessageType | undefined => {
    if (supportedTypes.includes(types as MessageType)) {
        return types as MessageType;
    }
    return undefined;
};

// 显示消息提示
const message = (text: string, types: string) => {
    const masstype = openmasstype(types);
    if (masstype) {
        ElMessage({
            message: text,
            type: masstype,
            plain: true
        });
    } else {
        // 如果传入的类型无效，以 warning 类型显示提示
        ElMessage({
            message: `不支持的消息类型: ${types}，将以警告形式展示`,
            type: 'warning',
            plain: true
        });
    }
};

export { message };
    